<?php
session_start();
include "../service/userService.php";

$secCode = isset($_POST["secCode"]) ? strtolower($_POST["secCode"]) : "";

if ($secCode == $_SESSION["securityCode"]) {
	unset($_SESSION["securityCode"]);
	
	$username = $_POST["userName"];
	if(isExistedUsername($_POST["userName"])){ 
		Header("Location: ../pc/register.php?msg=existed");
		exit;
	}
	$password = $_POST["pwd"];
	$fullName = $_POST["fullName"];
	$dob = $_POST["dob"];
	$phoneNumber = $_POST["phoneNumber"];
	$email = $_POST["email"];

	$result = insertUser($username, md5($password), 0, $fullName, $dob, $email, $phoneNumber);
	if(!$result)
		Header("Location: ../pc/register.php?msg=no");
	else
		Header("Location: ../pc/register.php?msg=ok");
} else {
	Header("Location: ../pc/register.php?msg=notmatch");
}
?>